package com.hao.tool.web.util;

import com.hao.tool.extra.cloud.module.ali.AliCloudManager;
import com.hao.tool.extra.cloud.module.ali.entity.AlCosResult;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * description
 *
 * @author RuiHaoZ on CMHK.jx
 * @date 2020-07-30 18:09
 */
public class AliCloudUtil {


    public void test2() throws Exception {
        String dir1 = "/Users/haol/develop/local-image/vehicle-image/G0004130010180";
        String dir2 = "/Users/haol/develop/local-image/vehicle-image/S0031130010010";
        String dir3 = "/Users/haol/develop/local-image/net";
        String dir4 = "/usr/local/static/audit_image/g1";
        upload(dir4);
    }

    public void upload(String filePath) throws FileNotFoundException {
        File file = new File(filePath);
        if (file.exists()) {
            if (file.isDirectory()) {
                for (File listFile : file.listFiles()) {
                    upload(listFile.getAbsolutePath());
                }
            } else {
                String localFilePath = file.getAbsolutePath();
                if (!localFilePath.contains("jpg")) {
                    return;
                }
                String upFilePath = localFilePath.replace("/usr/local/static/audit_image/g1",
                        "develop/image/vehicle/gantry/G00021100102100110055");
                AlCosResult alCosResult = AliCloudManager.buildCos(null, null)
                        .updateFile(new File(upFilePath).getParent() + "/", file.getName().toLowerCase(), new FileInputStream(file));
                System.out.println(alCosResult.getAccessUrl());
            }
        }

    }
}
